home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 271_02 / testints.c < prev    next >
Text File  |  1987-08-13  |  2KB  |  63 lines

  1. /*
  2. **          TEST PROGRAM FOR INTERRUPT HANDLER FUNCTIONS
  3. **  This program demonstrates the installable interrupt
  4. **  service routines contained in the ticker functions.
  5. **  The ticker routine installs on
  6. **  interrupt 1CH, and chains after completion to whatever
  7. **  routine may have already been hung on that interrupt.
  8. **  Ticker is not a C function as such, but a stand-alone assembly
  9. **  language routine which is installed by installtick() and removed
  10. **  by removetick().
  11. **
  12. **  Copyright 1987, S.E. Margison
  13. **
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <dos.h>
  18. #include <smdefs.h>
  19.  
  20.  
  21. int count;       /* this is the variable which ticker will manipulate */
  22.  
  23. main() {
  24.    int i;
  25.  
  26. /* Use installtick() to pass the desired variable address to the ticker
  27. ** process and install it upon the interrupt.
  28. */
  29.    installtick(&count);
  30.  
  31.  
  32. /* this loop demonstrates the use of the ticker function.  As long as
  33. ** the count variable is not 0, it will be decremented 18.21 times
  34. ** per second.  ticker tests the value for zero and if it is,
  35. ** does not decrement it again.  This makes it unnecessary to try to
  36. ** "trap" count exactly at zero before the next interrupt occurs.
  37. ** To use ticker, place a value in count (18 = 1 second more or less).
  38. ** Then, check it every so often to see if it is zero (or whatever
  39. ** your heart desires).
  40. */
  41.  
  42.    i = 0;
  43.    for ever {
  44.       if(kbhit()) {
  45.          if(getch() is 0x1b) break;  /* exit on ESCape */
  46.          }
  47.       count = 18;            /* set a value of 1 second */
  48.       while(count isnot 0);     /* loop until timed out */
  49.       printf("This is loop #%d\n", i++);  /* do something useful here */
  50.       }                      /* and go again */
  51.  
  52.  
  53. /* now, we have to clean up after ourselves.  It is necessary
  54. ** to restore the original vector table contents.  Alternate
  55. ** option is to turn off the power!!
  56. */
  57.     removetick();
  58.  
  59.  
  60.    }
  61.  
  62.  
  63.